﻿Imports System
Imports System.ComponentModel
Imports System.Workflow.ComponentModel.Compiler
Imports System.Workflow.ComponentModel.Design

Namespace System.Workflow.Activities
    Friend NotInheritable Class WebServiceInterfacePropertyDescriptor
        Inherits DynamicPropertyDescriptor
        ' Methods
        Friend Sub New(ByVal serviceProvider As IServiceProvider, ByVal pd As PropertyDescriptor)
            MyBase.New(serviceProvider, pd)
        End Sub

        Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
            Dim str As String = [TryCast](value,String)
            If ((Not str Is Nothing) AndAlso (str.Length > 0)) Then
                Dim service As ITypeProvider = DirectCast(MyBase.ServiceProvider.GetService(GetType(ITypeProvider)), ITypeProvider)
                If (service Is Nothing) Then
                    Throw New Exception(SR.GetString("General_MissingService", New Object() { GetType(ITypeProvider).FullName }))
                End If
                Dim type As Type = service.GetType([TryCast](value,String))
                If (type Is Nothing) Then
                    Throw New Exception(SR.GetString("Error_TypeNotResolved", New Object() { value }))
                End If
                Dim attribute As TypeFilterProviderAttribute = [TryCast](Me.Attributes.Item(GetType(TypeFilterProviderAttribute)),TypeFilterProviderAttribute)
                If (Not attribute Is Nothing) Then
                    Dim provider2 As ITypeFilterProvider = Nothing
                    Dim type2 As Type = Type.GetType(attribute.TypeFilterProviderTypeName)
                    If (Not type2 Is Nothing) Then
                        provider2 = [TryCast](Activator.CreateInstance(type2, New Object() { MyBase.ServiceProvider }),ITypeFilterProvider)
                    End If
                    If (Not provider2 Is Nothing) Then
                        provider2.CanFilterType(type, True)
                    End If
                End If
                value = type.AssemblyQualifiedName
            End If
            MyBase.RealPropertyDescriptor.SetValue(component, value)
        End Sub

    End Class
End Namespace

